package com.bolingcavalry.uschedule.config;

import com.winit.schedule.task.tracker.TaskTrackerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 *
 * @author wangjian
 * @date 17/8/23
 */
@Configuration

public class BeanConfig {
    @Bean
    public TaskTrackerFactoryBean taskTracker() throws IOException {
        TaskTrackerFactoryBean bean = new TaskTrackerFactoryBean();
        Properties properties = new Properties();
        try {
           properties.load(new FileInputStream("application.properties"));
        } catch (IOException e) {
            Resource resource = new ClassPathResource("application.properties");
            properties = PropertiesLoaderUtils.loadProperties(resource);
        }
        bean.setScanPackage("com.bolingcavalry.uschedule");
        bean.setConfigProps(properties);
        return bean;
    }
}
